home *** CD-ROM | disk | FTP | other *** search
- Path: locutus.rchland.ibm.com!usenet
- From: Philip Staite <pstaite@vnet.ibm.com>
- Newsgroups: comp.lang.c++
- Subject: Re: [Q] Converting dates in MMYY to YYMMDD format
- Date: Thu, 25 Jan 1996 10:41:34 -0600
- Organization: IBM Rochester, OS/2 Device Driver Team
- Message-ID: <3107B2BE.794B@vnet.ibm.com>
- References: <4e6ms8$ad5@walrus2.walrus.com>
- NNTP-Posting-Host: powertool.rchland.ibm.com
- Mime-Version: 1.0
- Content-Type: text/plain; charset=us-ascii
- Content-Transfer-Encoding: 7bit
- X-Mailer: Mozilla 2.0b4 (X11; I; AIX 1)
-
- Felipe Jordao wrote:
- >
- > Hi,
- >
- > I have a rather clumsy function that converts a character string in
- > MMYY format, (such as 1195 for November 1995) into a long DDMMYY
- > format, where DD is always the last day of the month. Hence "1282"
- > would be converted into 821231 (a long).
- >
- > Does anyone know a quick way of doing this (around 10-20 lines of
- > code)?#include<iostream.h>
- >
-
- Your example output looks like YYMMDD not DDMMYY... Anyway, try this:
-
- #include<iostream.h>
-
- long mn[ 12 ] = { 31, 28, 31, 30, 31, 30,
- 31, 31, 30, 31, 30, 31 };
-
- int main() {
- long n;
- cin >> n; // get date
- cout << ( mn[ n / 100 - 1 ] + ( n / 100 ) * 100 + ( n % 100 ) *
- 10000 ) << endl;
- return 0; }
-
-
-
-
- --
-
- Phil Staite, (507) 253-2529, team OS/2
- internet: pstaite@vnet.ibm.com internal: pstaite@rchland
-